import asyncio
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "/root/work/arcfox-crawler"))
from com.arcfox.manager.redis_task_manager import RedisTaskManager
from com.arcfox.util.redis_key_manager import YZY_BASIC_UNIVERSITY_SCHOOL_LIST_KEY, \
    YZY_UNIVERSITY_PROVINCE_SCHOOL_LIST_KEY
from loguru import logger
from com.arcfox.school.spider.yzy.yzy_university_score_spider import YZYUniversityScoreSpider
from com.arcfox.util.util import add_log


class YZYUniversityScoreService:
    def __init__(self):
        self.university_score_spider = YZYUniversityScoreSpider()
        self.task_manager = RedisTaskManager(YZY_UNIVERSITY_PROVINCE_SCHOOL_LIST_KEY)
        self.basic_task_manager = RedisTaskManager(YZY_BASIC_UNIVERSITY_SCHOOL_LIST_KEY)
        add_log(self.__class__.__name__ + ".log")

    async def start(self):
        tasks = await self.basic_task_manager.get_all_basic_tasks(True)
        if not tasks:
            logger.info("未获取到基础任务")
        else:
            logger.info("任务生成中...")
            await self.task_manager.add_tasks(tasks)
            await self.university_score_spider.start_crawl()


if __name__ == "__main__":
    asyncio.run(YZYUniversityScoreService().start())
